package org.softmed.action.builder;

import java.lang.reflect.Constructor;
import java.util.Iterator;
import java.util.List;

public class ActionStepBuilder {

	public Object getInstance(Class type, List<Object> parameters)
			throws Throwable {
		if (parameters == null || parameters.size() == 0)
			return type.newInstance();

		Class[] args = new Class[parameters.size()];

		int count = 0;
		for (Iterator iterator = parameters.iterator(); iterator.hasNext();) {
			Object object = (Object) iterator.next();
			args[count] = object.getClass();
			count++;
		}

		Constructor constructor = type.getConstructor(args);
		Object[] initArgs = parameters.toArray();
		return constructor.newInstance(initArgs);

	}

}
